﻿using UnityEngine;

namespace CinemaDirector
{
#if false
    /// <summary>
    /// Detaches all children in hierarchy from this Parent.
    /// </summary>
    [CutsceneItemAttribute("Cool", "Attach Children", CutsceneItemGenre.ActorItem)]
    public class CoolAttachChildrenEvent : CinemaActorEvent
    {
        
        public string ParentName = "";
        public GameObject[] Children;
        GameObject[] newChildren;
        public override void Trigger(GameObject actor)
        {
            if (actor != null && Children != null && ParentName != "")
            {
                var parent = Cool.Unity.Util.FindChildInGameObject(actor, ParentName);
                if (parent == null)
                    return;

                newChildren = new GameObject[Children.Length];
                int i = -1;
                foreach (GameObject child in Children)
                {
                    ++i;
                    newChildren[i] = GameObject.Instantiate(child) as GameObject;
                    newChildren[i].transform.parent = parent.transform;
                }
            }
        }

        public override void Reverse(GameObject actor)
        {
            for (int i = 0; i < newChildren.Length; ++i)
            {
                if (newChildren[i] != null)
                {
                    GameObject.DestroyImmediate(newChildren[i]);
                }
            }
            newChildren = null;
        }
    }
#endif
}